package com.definity.toolkit.ui.widget;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;

import javax.swing.JComboBox;

import com.definity.toolkit.ui.Body;
import com.definity.toolkit.ui.widget.model.WidgetComboBoxModel;

public class ComboBox extends JComboBox implements Widget<ComboBox> {

	private static final long serialVersionUID = 1770526756391291171L;

	public ComboBox() {
		super(new WidgetComboBoxModel());
	}

	@Override
	public String id() {
		return getName();
	}

	@Override
	public ComboBox id(String id) {
		setName(id);
		return this;
	}

	@Override
	public ComboBox properties(Body<ComboBox> body) {
		body.content(this);
		return this;
	}

	@Override
	public ComboBox size(int width, int height) {
		setPreferredSize(new Dimension(width, height));
		return this;
	}
	
	@Override
	public WidgetComboBoxModel getModel() {
		return (WidgetComboBoxModel) super.getModel();
	}
	
	public ComboBox addElement(Object item) {
		getModel().addElement(item);
		return this;
	}

	public ComboBox removeElement(Object item) {
		getModel().removeElement(item);
		return this;
	}
	
	public ComboBox addElements(Iterable<?> items) {
		for (Object item : items) {
			addItem(item);
		}
		return this;
	}

	@Override
	public Color background() {
		return getBackground();
	}

	@Override
	public ComboBox background(Color background) {
		setBackground(background);
		return this;
	}

	@Override
	public Color foreground() {
		return getForeground();
	}

	@Override
	public ComboBox foreground(Color foreground) {
		setForeground(foreground);
		return this;
	}

	@Override
	public Font font() {
		return getFont();
	}

	@Override
	public ComboBox font(Font font) {
		setFont(font);
		return this;
	}
	
}
